﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using MiniProfilerWebApplication1.Biz;
using MiniProfilerWebApplication1.Biz.Models;
using StackExchange.Profiling;
using StackExchange.Profiling.EntityFramework6;

namespace MiniProfilerWebApplication1
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            MiniProfilerEF6.Initialize();

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<TestDbContext>());
            using (var context = new TestDbContext())
            {
                context.Database.Initialize(true);

                context.Users.Add(new User()
                {
                    UserName = "admin",
                    StaffName = "张三",
                    StaffNo = "9527"
                });

                context.Categories.Add(new Category()
                {
                    CategoryName = "手机"
                });

                context.Products.Add(new Product()
                {
                    Price = 20.3M,
                    ProductName = "apple iphone 6s plus",
                    CategoryId = 1
                });

                context.SaveChanges();
            }
        }
        protected void Application_BeginRequest()
        {

            MiniProfiler.Start();

        }

        protected void Application_EndRequest()
        {

            MiniProfiler.Stop();

        }
    }
}
